﻿
var right_span = "<font color='green'>√</font>";
var sub_code = 0;
var t = 0;
function submited(ctx) {
	if(is_registered()==1||check_comfirm()==1||checkUnit()==1||checkName()==1||checkEmail()==1||cheakMobile()==1||cheak_randa()==1){
		return false;
	}else {
//		var form=document.getElementById("theForm");
		document.getElementById("theForm").action=ctx+"/message.do?method=addMessage";
		document.getElementById("theForm").submit();
	}
}
function is_registered() {
	var motive = document.getElementById("motive");
	var subMotive = document.getElementById("subMotive");

	if (motive.value == "") {
		subMotive.innerHTML = "请输入留言主题！";
		sub_code = 1;
	}else {
		subMotive.innerHTML = right_span;
		sub_code = 0;
	}
	return sub_code;
}

function check_comfirm() {
	var content = document.getElementById("content");
	var contentMsg = document.getElementById("contentMsg");
	if (content.value == "") {
		contentMsg.innerHTML = "请输入留言内容！";
		sub_code = 1;
	} else {
		contentMsg.innerHTML = right_span;
		sub_code = 0;
	}
	return sub_code;
}
function checkUnit() {
	var unit = document.getElementById("unit");
	var companyNameMsg = document.getElementById("companyNameMsg");

	if (unit.value == "") {
		companyNameMsg.innerHTML = "请输入单位名称！";
		sub_code = 1;
	} else {
		companyNameMsg.innerHTML = right_span;
		sub_code = 0;
			}
	return sub_code;
}

function checkName() {
	var userName = document.getElementById("userName");
	var nameMsg = document.getElementById("nameMsg");
	if (userName.value == "") {
		nameMsg.innerHTML = "请输入您的姓名！";
		sub_code = 1;
	} else {
		nameMsg.innerHTML = right_span;
		sub_code = 0;
	}
	return sub_code;
}

function checkEmail() {
	var email = document.getElementById("email");
	var emailMsg = document.getElementById("emailMsg");
	if (email.value == "") {
		emailMsg.innerHTML = "请输入邮箱！";
		sub_code = 1;
	} else {
		emailMsg.innerHTML = right_span;
		sub_code = 0;
	}
	return sub_code;
}
function cheak_randa(){
    var randa = document.getElementById("userrand");
    var code_notice = document.getElementById("code_notice");
    if(randa.value==""||randa.value=="请输入验证码"){
    	code_notice.innerHTML="请输入验证码!";
		sub_code=1;
	}else{
	var t = $.ajax(
			{
				url:"/ldtx/message.do?method=selectRada&randa=" + $("#userrand").val(),
				cache: false,
				async: false ,
				dataType:"text"			
			}).responseText; 
			if(t==1&&document.getElementById("userrand").value!=""){
				document.getElementById("code_notice").innerHTML = "验证码错误，请重新输入";
				sub_code=1;
			}
}
    return sub_code;
}
function cheakMobile() {
	var phoneNumber = document.getElementById("phoneNumber");
	var telMsg = document.getElementById("telMsg");
	if (phoneNumber.value == "") {
		telMsg.innerHTML = "请输入联系方式！";
		sub_code = 1;
	} else {
		telMsg.innerHTML = right_span;
		sub_code = 0;
	}
	return sub_code;
}
